home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / tlx_sq21.zip / NEWFILES.SLT < prev    next >
Text File  |  1992-03-20  |  8KB  |  234 lines

  1. //-----------------------------------------------------------
  2. // NEWFILES.SLT Get list of new files on this BBS.
  3. //
  4. // Please look at the comments through the whole file, and modify to
  5. // suit your needs, BEFORE you use it. Then recompile with CS NEWFILES.
  6. //-----------------------------------------------------------
  7.  
  8. // If you have suggestions for improving this script, please suggest
  9. // improvements to me via old-fashioned snail-mail to:
  10.  
  11. // Author:  Inge Vabekk
  12. //          Hamangskogen 108
  13. //          N-1300 SANDVIKA
  14. //          NORWAY
  15. //          tel. (472) 546 396
  16.  
  17. str logfile  [80]            // Log file name
  18.    ,shortname [8]            // Short name of BBS
  19.    ,Update     []="UPDATE$"  // Name of update program
  20.    ,command  [10]            // Command prompt
  21.    ,lline    [80]            // Help line
  22.                              // For the Global storage:
  23.    ,global   []="GLOBAL"     // Global script
  24.    ,PutLine  []="PUTLINE"    // PutLine script
  25.    ,bbstype  []="BTYPE"      // BBS type
  26.    ,short    []="SHORT"      // Short BBS name
  27.    ,version  []="BBSver"     // BBS version
  28.    ,newfil   []="NEWFIL"     // XBoard's New Files indicator
  29.    ,newmes   []="NEWMES"     // Directory for messages and new file list
  30.    ,code     []="CNAME"      // Code name for this BBS
  31.    ,prompt   []="PROMPT"     // Current command prompt
  32.    ;     
  33.  
  34. // Other constants and variables.
  35.  
  36. int file1
  37.    ,file2
  38.    ,file3
  39.    ,t1, t2, t3, t4, t5
  40.    ,more
  41.    ,tol = 300      // timeout limit 30 sec.
  42.    ,tmark, stat
  43.    ,mbbs, pcb, rbbs, opus, fido, crcs    // Possible BBS types
  44.    ,BBSver         // PCBoard version.
  45.    ,Enter=13       // Code for CR (Enter)
  46.    ;
  47.  
  48. //-----------------------------------------------------------
  49. // NewFiles script starts here.
  50. //-----------------------------------------------------------
  51.  
  52. main()
  53. {
  54.   entry();                               // Updates colors & status bar. 
  55.  
  56. // Check if online.
  57. //-----------------------------------------------------------
  58.  
  59.   if (!carrier())   
  60.   { prints ("T²: Sorry -- you can't get new files when you're offline!");
  61.     return (-1);
  62.   }
  63.   
  64. // Find BBS type (Set one logical variable).
  65.  
  66.   read (bbstype,shortname);              // Get BBS type,
  67.   mbbs = pcb = rbbs = opus = fido = crcs = 0;
  68.   if (shortname == "PCB" ) pcb = 1;
  69.   else if (shortname == "MBBS") mbbs = 1;
  70.   else if (shortname == "RBBS") rbbs = 1;
  71.   else if (shortname == "OPUS") opus = 1;
  72.   else if (shortname == "FIDO") fido = 1;
  73.   else if (shortname == "CRCS") crcs = 1;
  74.   else                                          
  75.   { prints ("T²: Sorry -- Unknown BBS type for the NewFiles script.");
  76.     return (-1);
  77.   }
  78.   read (version,logfile);                // Get version number too.
  79.   BBSver = subchr (logfile,0);
  80.  
  81.   read (prompt,command);                 // Get command prompt.
  82.   read (short,shortname);                // Get name of
  83.   logfile = "CAT\";                      // file list.
  84.   strcat (logfile,shortname);
  85.   if (filesize (logfile) == 0) fdelete (logfile);
  86.  
  87.   do
  88.   { terminal();                        // Process all echo
  89.     delay(3);                          // from the BBS.
  90.   } while (cinp_cnt() > 0);
  91.  
  92.   capture ("*CLOSE*");                 // Close capture file.
  93.   newdir (_telix_dir); // Make sure we're in the TELIX main directory.
  94.   logfile = "LOG\TEMP.SQR";            // Create a temporary file
  95.                                        // in the logfile directory.
  96.   fdelete (logfile);                   // Delete previous file.
  97.   capture (logfile);                   // Start new capture.
  98.   
  99.   t5 = track ("^J",0);                 // Track linefeeds 
  100.   if (mbbs)
  101.   { t2 = track ("-more-",0);           // More?
  102.     t3 = track (">=none :",0);         // Track directory prompt
  103.     t4 = track ("YYMMDD",0);           // Track date
  104.     call (PutLine,"F N",Enter);        // Go get the new files.
  105.   }
  106.   else if (pcb)
  107.   { t2 = track ("lag, More?",0);       // More prompt?
  108.     t3 = track ("to continu",0);       // Enter to continue?
  109.     t4 = track ("ning Direc",0);       // No date for PCB.
  110.     call (PutLine,"N S A NS",Enter);   // Go get the new files.
  111.   }
  112.   t1 = track (command,0);              // Track Command.
  113.  
  114.   tol = 150;                           // Set 15 sec. timeout.
  115.   more = 0;
  116.   tmark = timer_start (tol);
  117.  
  118.   while ((stat=trig()) > 0)
  119.   { if (stat == t1)                    // Command - done.
  120.       break;         
  121.  
  122.     if (pcb)
  123.     { if (stat==t2 || stat==t3)        // Continue or more
  124.       { more = 1;
  125.         call (PutLine,"NS",Enter);     // Non-Stop.
  126.       }
  127.     }
  128.     else if (mbbs)
  129.     { if (stat==t2)
  130.       { more = 1;
  131.         cputc (Enter);                 // Continue.
  132.       }
  133.       else if (stat==t3)               // What directories?
  134.         call (PutLine,"*",Enter);      // All.
  135.  
  136.       else if (stat==t4)               // Date...
  137.         cputc (Enter);
  138.     }
  139.   }
  140.  
  141.   timer_free (tmark);                  // free timer channel
  142.   track_free (0);                      // and all track channels.
  143.   tol = 300;                           // Restore timeout.
  144.   capture ("*CLOSE*");                 // Close the temporary log file.
  145.  
  146.   if (read (newfil,lline) > 0)         // New files wanted:
  147.   { t1 = fopen (logfile,"r");          // Open temporary file.
  148.     read (newmes,logfile);
  149.     read (code,lline);
  150.     strcat (logfile,lline);
  151.     strcat (logfile,".NEW");
  152. //  prints (logfile);
  153.     t2 = fopen (logfile,"w");          // Open XBoard's list.
  154.     while (fgets(logfile,strmaxlen(logfile),t1) >=0)
  155.     { fputs (logfile,t2);
  156.       fputs ("^M^J",t2);
  157.     }
  158.     fclose (t1);
  159.     fclose (t2);
  160.   }
  161.  
  162.   exec (Update,shortname);             // Update log + cat files.
  163.   logfile = "LOG\";
  164.   strcat (logfile,shortname);          // Find name of log file.
  165.   capture (logfile);                   // Start new capture.
  166.   if (more)
  167.   { if (mbbs)
  168.       call (PutLine,"Q U L 0",Enter);  // Stop this prompt for later.
  169.     else if (pcb)
  170.       call (PutLine,"P 0",Enter);      // Stop this prompt for later.
  171.     waitfor (command,2);
  172.   }
  173.   return (0);                            // Return OK.
  174. }
  175.  
  176. //-----------------------------------------------------------
  177. // Routine to update colors and status bar.
  178. //-----------------------------------------------------------
  179.  
  180. entry ()
  181. {
  182.   _back_color = 1;
  183.   _fore_color = 14;
  184.   update_term();
  185. }
  186.  
  187. //-----------------------------------------------------------
  188. //  Trig loop. Waits here until either one "trig string" is
  189. //  found, or we have a time-out, or carrier is lost.
  190. //-----------------------------------------------------------
  191.  
  192. trig()
  193. {
  194. int i;
  195.   do
  196.   { terminal();
  197.   }  while (!time_up (tmark)             // Loop until time-out
  198.           && carrier()                   // or carrier lost
  199.           && (i=track_hit(0))==0);       // or we trigged.
  200.   if (i==0) 
  201.     i = -1;                              // Error!
  202.   else
  203.     timer_restart (tmark,tol);           // Restore timer.
  204.   return (i);
  205. }
  206.  
  207. //-----------------------------------------------------------
  208. // Read a global variable.
  209. //-----------------------------------------------------------
  210.  
  211. read (str name, str varname)
  212. {
  213.   return (call (global,"R",name,varname));
  214. }
  215.  
  216. //-----------------------------------------------------------
  217. // Execute a program.
  218. //-----------------------------------------------------------
  219.  
  220. exec (str prog,str pram)
  221. {
  222. str line [80];
  223. int i;
  224.   i = run (prog,pram,2);               // Try to run program.
  225.   if (i >= 0) return (i);              // OK.
  226.  
  227.   line = "Couldn't find or execute '";
  228.   strcat (line,prog);
  229.   strcat (line,".EXE'!");
  230.   tone (80,80);                        // No success:
  231.   status_wind (line,20);
  232.   return (i);
  233. }
  234.